package ar.com.duam.porky.movil.tasks;

import static ar.com.duam.porky.movil.ConstantesPorky.URL_PORKY;

import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.http.HttpStatus;

import android.os.AsyncTask;
import android.util.Log;

public class WebServiceAvailableTask extends AsyncTask<Void, Void, Boolean> 
{

	@Override
	protected Boolean doInBackground(Void... params) 
	{
		try
		{
			URL url = new URL(URL_PORKY);
			HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

			Log.d("isWebServiceAvailable", "El status debería ser 200 y es: "+ urlConnection.getResponseCode());
			
			return HttpStatus.SC_OK == urlConnection.getResponseCode();
		}
		catch (Exception e)
		{
			Log.e("isWebServiceAvailable", "Error testeando la conexión", e);
			
			return false;
		}
	}

}
